﻿/*----------------------------------------------------------------
// Copyright (C) 2016 通通优品版权所有。
// 命名空间: STOWaybillMall.Dapper.Repositories
// 类名：ProductInfoRepository
// 功能描述：N/A
// 
// 创建标识：Roc.Lee(李鹏鹏) 2017/8/9 15:29:37 TEC-ROCLEE Roc.Lee

// 修改标识：
// 修改描述：
// 
//
//----------------------------------------------------------------*/
using Abp.Dapper.Repositories;
using STOWaybillMall.Core;
using STOWaybillMall.IRepositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.EntityFramework;
using STOWaybillMall.Domain.Products.Model;
//using Dapper.Mapper;
using Dapper;

namespace STOWaybillMall.Dapper.Repositories
{
    public class ProductInfoRepository : STOWaybillMallRepositoryBase<ProductInfo, long>, IProductInfoRepository
    {
        public ProductInfoRepository(IDbContextProvider<STOWaybillMallDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public  IList<ProductInfo> GetProductDetail(long productid)
        {
            return ((Query("select * from ProductInfo where ProductID=@ProductID", new { ProductID = productid }))).ToList();
        }

        public IList<ProductListInfoDto> GetProductList()
        {
            return (Connection.Query<ProductListInfoDto, ImageInfo, ProductListInfoDto>(
                "select top 100 pb.ProductCategory as ProductCategoryID,pb.ProductName ProductName,pb.BuyLeast BuyLeast,pb.Unit Unit,p.ProductID ProductID,p.SpecPropGroupName SpecPropGroupName,p.DefaultPrice DefaultPrice,im.URI URI  from ProductBaseInfo pb join ProductInfo p on p.ProductBaseID=pb.ProductBaseID left join ImageInfo im on im.ImageID=pb.ImageID order by pb.ProductCategory",
                splitOn: "DefaultPrice",
                map: (dto, im) =>
                {
                    dto.ProductPic = im.URI;
                    return dto;
                })).ToList();
        }
    }
}
